<style scoped>
    .layui-row {
        overflow: hidden;
    }
    .select-item {
        width: 34.333333%;
        float: right;
    }
    .layui-row:after, .layui-row:before {
        clear: none;
    }
    .layui-form >>> .layui-form-select{
        z-index: inherit;
    }
    .layui-table, .layui-table-view {
          margin: 20px 0;
    }.item-fount-color{
     color: #009688;
        font-size: 20px;
        padding: 3px 3px 3px 0.5%;
     }
</style>

<template>
    <div class="department">
        <table   class="layui-table" style="border-collapse: collapse;" >
            <tbody>
            <tr>
                <table class="layui-table layui-form"   >

                    <thead>
                    <tr >
                        <td colspan="10"><p class="item-fount-color">损耗</p></td>
                    </tr>
                    <tr>
                        <th >品种规格</th>
                        <th >产品数量（包/箱/件）</th>
                        <th >当日产量(吨)</th>
                        <th >当日单价（元/吨）</th>
                        <th>当日销售额（元）</th>
                        <th >备注</th>
                    </tr>
                    </thead>

                    <tbody>

                    <tr class="id9" v-for="(val, index) in whoutform" >
                        <template v-if="val.datacategoryfirst.startsWith('007') ">
                            <td >{{val.parmname3}}</td>
                            <td >{{val.value1}}</td>
                            <td>{{val.value2}}</td>
                            <td>{{val.value3}}</td>
                            <td>{{val.amount}}</td>
                            <td>{{val.remark}}</td>
                        </template>
                    </tr>
                    </tbody>


                </table>
            </tr>
            </tbody>
        </table>
<!--        <Pagination :cur="currentPage" :all="totalPage" :callback="turnPage" ></Pagination>-->
    </div>
</template>

<script>
    import Pagination from '../common/Pagination.vue'
    export default {
        name: 'Productiondaily',
        props: ['id'],
        components: {Pagination},
        data () {
            return {
                departments: [],
                currentPage: 1,
                rows: 10,
                totalPage: 0,
                searchName: '',
                afterList: [],
                storehouseroom:[],
                storeroom:[],
                starttime:"",
                endtime:"",
                srguid:"",
                shrguid:"",
                whoutform:[],
                exportpage:1,
                orgids:[],
                departids:[],
                departid:"",
                dailydata:"",
                storerooms:[],
                productiondaily:{},
                guid : this.id,
            }
        },
        mounted() {
            let that = this;
            this.getPageData();
         },
        updated: function () {
            layui.form.render('select');
            layui.form.render();

        },
        methods: {
            // 数据转换
            tansList () {
                this.afterList = Object.values(this.whoutform.reduce((temp, item) => {
                    if( temp[item.parmname1] ) {
                        temp[item.parmname1].push(item)
                    }else {
                        temp[item.parmname1]  = [item]
                    }
                    return temp
                },{}))
            },
            search: function() {
                this.getPageData('search');
                console.log(this);
            },
            turnPage: function(data){
                this.exportpage = data
                this.currentPage = data;
                this.getPageData();
            },
            getPageData: function(type = '') {
                var that = this;

                let loader = layui.layer.load();

                let postData = {rows: that.rows};
                if (type != 'search') {
                    postData.page = that.currentPage;
                }
                    postData.guid = that.guid;
                $.ajax({
                    url: '/produce/ProductionDaily!getDailyDataItem.action',
                    type: "post",
                    data: postData,
                    dataType: "json",
                    success: function(res) {
                            if (res.info != 'error'  ) {
                                if(res.info.items ==undefined){
                                    that.toast("未找到相应信息，请重新选择查选条件");
                                }else {
                                    //分页数据赋值
                                    that.currentPage = res.info.items.indexPage;
                                    that.totalPage = res.info.items.pageCount;
                                    that.whoutform = res.info.items.rows;
                                    that.productiondaily = res.info.productiondaily;
                                    that.tansList()
                                }
                            } else {
                                that.alert("系统错误");
                            }

                    },
                    complete: function () {
                        layer.close(loader);
                    }
                });
            },compare: function (property){
                return function(a,b){
                    var value1 = a[property];
                    var value2 = b[property];
                    return value1 - value2;
                }
            },
            add: function () {
                this.$parent.switchPage('addSalesPermission');
            },
            exportExcel:function (){
                var that = this;
                let postData = {rows: that.rows};
                that.starttime = $('#starttime').val();
                that.endtime = $('#endtime').val();
                that.srguid =  $('#srguid').val();
                that.shrguid =  $('#shrguid').val();
                window.location.href="/sales/Whoutform!exportOrderData.action?starttime=" + that.starttime + "&endtime=" + that.endtime + "&srguid=" + that.srguid +"&shrguid="+ that.shrguid+ "&rows=" + that.rows +  "&page=" + this.exportpage
            },
            edit: function (id) {
                this.$parent.gid = id;
                this.$parent.switchPage('EditDepartment');
            },
            del: function (id) {
                let that = this;
                layer.confirm('确定要删除该数据吗？', function () {
                    let loader = layer.load();
                    $.ajax({
                        url: '/sales/Salespermission!del.action',
                        type: "post",
                        data: {guid: id},
                        dataType: "json",
                        success: function(res) {
                            if (res.info == "ok") {
                                that.toast("删除成功");
                                that.getPageData('search');
                            } else {
                                that.toast("系统错误");
                            }
                        },
                        complete: function () {
                            layer.close(loader);
                        }
                    });
                })
            },uniqueJsonArray:function(){
                var result = [array[0]];
                for(var i = 1; i < array.length; i++){
                    var item = array[i];
                    var repeat = false;
                    for (var j = 0; j < result.length; j++) {
                        if (item[key] == result[j][key]) {
                            repeat = true;
                            break;
                        }
                    }
                    if (!repeat) {
                        result.push(item);
                    }
                }
                return result;
            }

        }
    }
</script>
